import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_refresh.dart';
import '../../api/cabinetFormApi.dart';
import '../../model/cabinet_form_deliver_model.dart';
import '../../views/cabinet_form_deliver_item.dart';
import 'logic.dart';

class CabinetFormDeliverPage extends StatefulWidget {
  const CabinetFormDeliverPage({Key? key}) : super(key: key);

  @override
  State<CabinetFormDeliverPage> createState() => _CabinetFormDeliverPageState();
}

class _CabinetFormDeliverPageState extends State<CabinetFormDeliverPage> {
  final CabinetFormDeliverLogic logic = Get.put(CabinetFormDeliverLogic());
  ScrollController _headerController = ScrollController();
  ScrollController _controller = ScrollController();

  int page = 1;
  String startTime = "";
  String endTime = "";

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _headerController.addListener(() {
      _controller.jumpTo(_headerController.offset);
    });
    startTime = Get.arguments["startTime"];
    endTime = Get.arguments["endTime"];
    logic.firstShowGuidWidget();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: HLAppBar(navigationTitle: "柜机投递报表"),
          body: Column(
            children: [
              CabinetFormDeliverItem(
                controller: _headerController,
              ),
              Expanded(
                  child: HLRefresh<CabinetDeliverListModel>(
                pageCount: 50,
                onLoading: () async {
                  page += 1;
                  return await CabinetFormApi.deliverList(page: page, startTime: startTime, endTime: endTime);
                },
                onRefresh: () async {
                  page = 1;
                  return await CabinetFormApi.deliverList(page: page, startTime: startTime, endTime: endTime);
                },
                snap: (date, int index) {
                  return CabinetFormDeliverItem(
                    controller: _controller,
                    isScroll: false,
                    model: date,
                  );
                },
              ))
            ],
          )),
    );
  }

  @override
  void dispose() {
    Get.delete<CabinetFormDeliverLogic>();
    super.dispose();
  }
}
